package cn.nju.sirx.algorithm.sort;

/**
 * Direct insertion sort.
 * 
 * @author SirX
 */
public class DirectInsertionSort implements ISort {

	@Override
	public <T extends Comparable<? super T>> void sort(T[] data) {
		for (int i = 1; i < data.length; i++) {
			for (int j = 0; j < i; j++) {
				if (data[i].compareTo(data[j]) < 0) {
					T tmp = data[i];
					for (int k = i; k > j;) {
						data[k] = data[--k];
					}
					data[j] = tmp;
				}
			}
        }
    }

}
